﻿using BLL.Interfaces;
using DAL;
using GUI.Models;
using POCOS;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

namespace GUI.Controllers
{
    public class TestController : Controller
    {
        //
        // GET: /Test/
        private AuteurContext db = new AuteurContext();
        private IArticlesServices _articleServices;

        public TestController(IArticlesServices articleServices)
        {
            _articleServices = articleServices;
        }

        [Authorize]
        public ActionResult Index()
        {
            int id = WebSecurity.CurrentUserId;
            Session["idUser"] = id;
            return View();
        }


        //public JsonResult ArticleList(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        //{
        //    try
        //    {
        //        Thread.Sleep(200);
        //        int articlcount = _articleServices.GetArticleCount();
        //        var articles = _articleServices.GetArticles(jtStartIndex, jtPageSize, jtSorting);


        //        //_articleServices._articleServices
        //        int id = Convert.ToInt32(Session["idUser"]);
        //        string name = _articleServices.GetAuthorName(id);
        //        var result = from x in articles

        //                     select new ArticleModel
        //                     {
        //                         Id = x.Id,
        //                         Title = x.Title,
        //                         CreationDate = x.CreationDate,
        //                         ArticleContenent = x.ArticleContenent
                                
        //                     };
        //        return Json(new { Result = "OK", Records = result, TotalRecordCount = articlcount }, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception ex)
        //    {
        //        return Json(new { Result = "ERROR", Message = ex.Message });
        //    }
        //}

        //[HttpPost]
        //public JsonResult GetArticlesByFilter(string title = "", int auteurid = 0, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        //{
        //    try
        //    {
        //        var studentCount = _articleServices.GetArticleCountByFilter(title, auteurid);
        //        var students = _articleServices.GetArticlesByFilter(title, auteurid, jtStartIndex, jtPageSize, jtSorting);
        //        return Json(new { Result = "OK", Records = students, TotalRecordCount = studentCount });
        //    }
        //    catch (Exception ex)
        //    {
        //        return Json(new { Result = "ERROR", Message = ex.Message });
        //    }


        //}

        //[HttpPost]
        //public JsonResult CreateArticle(Article article)
        //{
        //    try
        //    {
        //        if (!ModelState.IsValid)
        //        {
        //            return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });
        //        }


        //        _articleServices.CreateArticle(article);
        //        return Json(new { Result = "OK", Record = article });
        //    }
        //    catch (Exception ex)
        //    {
        //        return Json(new { Result = "ERROR", Message = ex.Message });
        //    }
        //}


        //[HttpPost]




        //public JsonResult UpdateArticle(ArticleModel Model)
        //{

        //    var article = _articleServices.GetArticleById(Model.Id);

        //    if (article == null)
        //    {
        //        return Json(new { Status = "Failed" }, JsonRequestBehavior.AllowGet);
        //    }
        //    else
        //    {
        //        article.Id = Model.Id;
        //        article.Title = Model.Title;
        //        article.CreationDate = Model.CreationDate;
               
        //        _articleServices.UpdateArticle(article);

        //      return Json(new { Result = "OK" });
        //    }
        //}






        //public JsonResult DeleteArticle(ArticleModel Model)
        //{
    
        //        _articleServices.DeleteArticle(Model.Id);
        //        return Json(new { Result = "OK" });
         

        //}


    }
}
